<template>
    <el-dialog :visible.sync="show" width="50%" @click="show = false" class="subDialo">
      <el-form label-width="180px" :model="editForm">
        <el-row>
          <el-col :span="12" v-if="!disabled">
            <el-form-item label="科室名称" class="tip">
              <el-input class="flex-1" size="small" v-model="editForm.name" auto-complete="off" placeholder="请输入科室名称"></el-input>
            </el-form-item>
            <el-form-item label="一级科室" class="tip">
              <el-input class="flex-1" size="small" v-model="editForm.parent_name" disabled auto-complete="off" placeholder="请输入职员姓名"></el-input>
            </el-form-item>
            <el-form-item label="科室号" class="tip">
              <el-input class="flex-1" size="small" v-model="editForm.code" auto-complete="off" placeholder="请输入科室号" ></el-input>
            </el-form-item>
            <el-form-item label="科室层级1" class="tip">
              <el-select v-model="editForm.type_lv1" placeholder="请选择科室层级1">
                <el-option
                  v-for="item in type_lv1"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="科室层级2" class="tip">
              <el-select v-model="editForm.type_lv2" placeholder="请选择科室层级2">
                <el-option
                  v-for="item in type_lv2"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="科室层级3" class="tip">
              <el-select v-model="editForm.type_lv3" placeholder="请选择科室层级3">
                <el-option
                  v-for="item in type_lv3"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12" v-else>
            <el-form-item label="二级科室：">
              <span >{{editForm.department.name}}</span>
            </el-form-item>
            <el-form-item label="职员姓名：">
              <span >{{editForm.name}}</span>
            </el-form-item>
            <el-form-item label="工号：">
              <span >{{editForm.code}}</span>
            </el-form-item>
            <el-form-item label="人员类别：">
              <span >{{(editForm.type)}}</span>
            </el-form-item>
            <el-form-item label="岗位系数：">
              <span >{{editForm.coefficient}}</span>
            </el-form-item>
            <el-form-item label="岗位：">
              <span>{{editForm.position}}</span>
            </el-form-item>
          </el-col> -->
        </el-row>
      </el-form>
      <div slot="footer" v-if="!disabled">
        <el-button @click="show = false">取 消</el-button>
        <el-button type="primary" @click="submit" :loading="btnLoading">确 定</el-button>
      </div>
    </el-dialog>
</template>

<script>
import { debounce } from "@/utils";
import {type_lv1,type_lv2,type_lv3} from '@/assets/js'
export default {
    props:{
        btnLoading:{
          default:false,
        },
        disabled:{
            default:false,
        },
        editForm:{
            default:()=>({})
        }
    },
    data(){
        return {
          show: false,
          type_lv1,
          type_lv2,
          type_lv3,
          rules:['name','parent_id','code','type_lv1','type_lv2','type_lv3']
        }
    },
    methods:{
        submit :debounce(function(){
          if(this.btnLoading) return
          for (const key of this.rules) {
            if(!this.editForm[key] && this.editForm[key] !== 0){
              this.$message({
                type: "error",
                message: "请填写全部信息!",
              });
              return
            }
          }
          this.$emit('submit',this.editForm)
        },500,true)
    }
}
</script>

<style lang='less'>
.subDialo{
  .el-col-12{
    width: 70%;
  }
  .el-form-item__label{
    display: inline-block;
    white-space: nowrap;
    min-width: 120px;
  }
  .el-form-item__content{
    display: flex;
    .span{
      margin-left: 8px;
      font-size: 12px;
    }
  }
}

</style>